---
title: Migrate
description: Applies all outstanding migrations from a directory to the target database.
---

## Command

Assuming that migrations up to and including migration `40_create_enum_type` from the [example migrations](https://github.com/xataio/pgroll/tree/main/examples) directory have been applied, running:

```
$ pgroll migrate examples/
```

will apply migrations from `41_add_enum_column` onwards to the target database.

If the `--complete` flag is passed to `pgroll migrate` the final migration to be applied will be completed. Otherwise the final migration will be left active (started but not completed).

If any of the migration files are incompatible with your `pgroll` version, the command will report the errors and exit before running any migrations.

## Backfill Configuration

When migrations involve backfilling data (such as adding a `NOT NULL` constraint to an existing column), the backfill process can be controlled using these flags:

- `--backfill-batch-size`: Number of rows backfilled in each batch (default: 1000)
- `--backfill-batch-delay`: Duration of delay between each batch, e.g., "1s", "1000ms" (default: 0s)

```
$ pgroll migrate examples/ --backfill-batch-size 500 --backfill-batch-delay 100ms
```

These options help manage the performance impact of large backfill operations by processing data in smaller batches with optional delays between batches.

## Existing Database Schema

If you attempt to run `pgroll migrate` against a database that has existing tables but no migration history, the command will fail with an error message. In this case, you should first run `pgroll baseline` to establish a baseline migration that captures the current schema state before applying any new migrations.
